home *** CD-ROM | disk | FTP | other *** search
-
- #include "swar.h"
-
- InitShots()
- {
- extern RGBColor myWhite, myBlack, myRed, myBlue, myYellow, myGreen, myOrange, myGray, myDkBlue;
- extern SHOTREC gShotRecs[MAX_SHOTS], gOldShotRecs[MAX_SHOTS];
- short i, nc;
-
- for (i = 0; i < MAX_SHOTS; i++) {
- gShotRecs[i].where.v = -1;
- gShotRecs[i].where.h = -1;
- gShotRecs[i].vel.v = -1;
- gShotRecs[i].vel.h = -1;
- gShotRecs[i].lifeSpan = 0;
- gShotRecs[i].isAlive = FALSE;
- } /* for */
-
-
- } /* InitShots() */
-
- CreateShot(c, h, v, hv, vv)
- RGBColor c;
- short h, v, hv, vv;
- {
- short i;
-
- for (i = 0; i < MAX_SHOTS; i++)
- if (!gShotRecs[i].isAlive) {
- gShotRecs[i].where.v = v;
- gShotRecs[i].where.h = h;
- gShotRecs[i].vel.v = vv;
- gShotRecs[i].vel.h = hv;
- gShotRecs[i].isAlive = TRUE;
- gShotRecs[i].lifeSpan = 20;
- gShotRecs[i].color = c;
- return;
- } /* if */
-
-
- } /* CreateShot() */
-
- MoveShots()
- {
- short i;
- extern SHOTREC gShotRecs[MAX_SHOTS];
-
- for (i = 0; i < MAX_SHOTS; i++)
- if (gShotRecs[i].isAlive) {
- if (gShotRecs[i].lifeSpan) {
- gShotRecs[i].lifeSpan--;
- gShotRecs[i].where.h += gShotRecs[i].vel.h;
- gShotRecs[i].where.v += gShotRecs[i].vel.v;
- if (gShotRecs[i].where.h > 637) {
- gShotRecs[i].vel.h *= -1;
- gShotRecs[i].where.h = 637;
- } /* if */
- if (gShotRecs[i].where.h < 1) {
- gShotRecs[i].vel.h *= -1;
- gShotRecs[i].where.h = 1;
- } /* if */
- if (gShotRecs[i].where.v > 477) {
- gShotRecs[i].vel.v *= -1;
- gShotRecs[i].where.v = 477;
- } /* if */
- if (gShotRecs[i].where.v < 21) {
- gShotRecs[i].vel.v *= -1;
- gShotRecs[i].where.v = 21;
- } /* if */
- } /* if */
- else
- gShotRecs[i].isAlive = FALSE;
- } /* if */
-
- } /* MoveShots() */
-
- DrawShots()
- {
- GrafPtr savePort;
- extern CGrafPort *gOSPtr;
- short i, j;
- extern RGBColor myBlack;
- Rect dstRect;
- extern SHIPREC gShipRecs[MAX_PLAYERS];
-
- GetPort(&savePort);
- SetPort((GrafPtr)gOSPtr);
- for (i = 0; i < MAX_SHOTS; i++) {
- if (gOldShotRecs[i].isAlive)
- SetCPixel(gOldShotRecs[i].where.h, gOldShotRecs[i].where.v, &myBlack);
- if (gShotRecs[i].isAlive) {
- SetCPixel(gShotRecs[i].where.h, gShotRecs[i].where.v, &(gShotRecs[i].color));
- gOldShotRecs[i] = gShotRecs[i];
- dstRect.top = gShotRecs[i].where.v;
- dstRect.left = gShotRecs[i].where.h;
- dstRect.bottom = dstRect.top + 1;
- dstRect.right = dstRect.left + 1;
- for (j = 0; j < MAX_PLAYERS; j++)
- if (!ColorsEqual(gShotRecs[i].color, gShipRecs[j].color))
- if (CheckForShipCollision(j, dstRect)) {
- gShotRecs[i].isAlive = FALSE;
- KillPlayer(j);
- } /* if */
- } /* if */
- } /* for */
- SetPort((GrafPtr)savePort);
-
- } /* DrawShots() */
-